﻿// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

struct Display {
    void operator()(pair<string, double> info) {
        cout << "科目: " << info.first << " 成绩: " << info.second << endl;
    }
};

int main()
{
    //创建一个保存成绩的map
    map<string, double> StuScore;
    //向map中添加数据
    StuScore["python"] = 90.5;
    StuScore["php"] = 88.5;
    StuScore["java"] = 85.5;
    StuScore.insert(map<string, double>::value_type("go", 95.5));

   /* for (auto& w : StuScore) {
        cout << w.first << " " << w.second << endl;
    }*/

    //for_each(StuScore.begin(), StuScore.end(), Display());

    //在map中查找数据 find()
    //map<string, double>::iterator it;
    //it = StuScore.find("java");
    //if (it != StuScore.end()) {
    //    //it迭代器  
    //    cout << it->second << endl;
    //}
    //else {
    //    cout << "NOT FOUND" << endl;
    //}

    //在map中删除数据 erase
    
    map<string, double>::iterator it = StuScore.begin();
    for (; it != StuScore.end(); ) {
        if (it->second <= 90) {
            it = StuScore.erase(it);  
        }
        else {
            ++it;
        }
    }
    for_each(StuScore.begin(), StuScore.end(), Display());



}


